﻿// -----------------------------------------------------------------------
// <copyright file="CastomerAddCommand.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ShopShell.CustomerCommands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Input;
    using Microsoft.Practices.ServiceLocation;
    using Microsoft.Practices.Prism.Regions;
    using ModuleCustomer.View;
    using Microsoft.Practices.Unity;
    using ShellInfrastructure;
    using ModuleCustomerEdit.View;
    using ServerConnection.ShopServiceReference;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomerAddCommand : ICommand
    {
        [Dependency]
        public IRegionManager RegionManager { get; set; }

        public bool CanExecute(object parameter)
        {
            bool canExecute = true;
            canExecute &= ServerConnection.Service.CurrentUser.Role == UserRole.Administrator;
            return canExecute;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            RegionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

            IRegion region = RegionManager.Regions[RegionNames.LeftRegionName];
            ICustomerViewList obj = ServiceLocator.Current.GetInstance<ICustomerViewList>();

            IRegion region1 = RegionManager.Regions[RegionNames.RightRegionName];
            ICustomerEdit obj1 = ServiceLocator.Current.GetInstance<ICustomerEdit>();


            if (parameter.ToString() == "1" && obj.Selected() != null)
            {
                obj1.Load(obj.Selected());
            }
            else
            {
                obj1.Load(new User());
            }
            region1.Activate(obj1);
        }
    }
}
